package com.herr.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PersonService {
    //自动注入，根据类名type来找。如需要根据name进行，需要配合@Qualifier
    //使用注解方式时不需要set方法
    @Autowired
    private PersonDao personDao;

    //@Resource，@Inject，为JSR提供的注解，默认使用name进行匹配
    @Resource(name = "personDao123")
    private PersonDao personDao123;

    public void printNameByAutowired(){
        System.out.println(personDao);
        personDao.printName();
    }

    public void printNameByResource(){
        System.out.println(personDao123);
        personDao123.printName();
    }

}
